//
//  EmoticonTextAttachment.swift
//  表情键盘布局
//
//  Created by x on 2017/7/19.
//  Copyright © 2017年 HLB. All rights reserved.
//

import UIKit

class EmoticonTextAttachment: NSTextAttachment {

    //保存文字对应的表情
    var chs: String?
    
    class func imageText(emoticon: Emoticons, font:UIFont) -> NSAttributedString {
        //2.1创建一个附件
        let attachment = EmoticonTextAttachment()
        attachment.chs = emoticon.chs
        //设置附件图片的大小
        attachment.bounds = CGRect(x: 0, y: -4, width: font.lineHeight, height: font.lineHeight)
        attachment.image = UIImage.init(contentsOfFile: emoticon.emoticonPath!)
        
        //2.2根据附件创建属性字符串
        return NSAttributedString(attachment: attachment)
    }
}
